function time = advanceTime(t, ts)
% This function computes a new time struct given an old time struct and the
% time step.
% INPUTS
    % t: a time struct with fields 'year', 'month', 'day', 'hour', 'min',
    % and 'sec'
    % ts: a time step in seconds
% OUTPUT
    % time: the new time struct
    
y=t.year; mo=t.month; d=t.day; h=t.hour; min=t.min; s=t.sec;
temp_s=0; temp_min=0; temp_hr=0; temp_day=0; temp_mo=0; temp_yr=0;

time.UTC = t.UTC;

% Advance and propegate
if(s+ts>=60)
    temp_s = s+ts-60;
    time.sec = temp_s;
    temp_min = 1;
else
    time.sec = s+ts;
end
if(min+temp_min==60)
    time.min = 0;
    temp_hr = 1;
else
    time.min = min + temp_min;
end
if(h+temp_hr==24)
    time.hour = 0;
    temp_day = 1;
else
    time.hour = h + temp_hr;
end
if(d+temp_day>=28)
    switch mo
        case 1
            if(d+temp_day==32)
                time.day = 1;
                time.month = 2;
            else
                time.day = d+temp_day;
            end
        case 2
            %
        case 3
            %
        case 12
            % need to advance the year here
    end
else
    % If the date is less than 28, just advance 
    time.day = d+temp_day;
    time.month = mo;
    time.year = y;
end